import {onMounted, onUnmounted, ref} from 'vue'
import {useIntersectionObserver} from '@vueuse/core'
export function useLazyData(apiFn: () => void) {
    const target = ref(null)
    const {stop} = useIntersectionObserver(target,([{isIntersecting}]) => {
            if(isIntersecting){
                stop()
                apiFn()
            }
    },{
        threshold:0
    })
    return target
}
export function useHMScrollY() {
    const y = ref(0)
    const onScroll = () => {
        const scrollTop = 
        document.documentElement.scrollTop || document.body.scrollTop
        y.value = scrollTop
    }
    onMounted(()=> {
        window.addEventListener('scroll',onScroll)
    })
    onUnmounted(()=> {
        window.removeEventListener('scroll',onScroll)
    })
    return y
}